package com.it.myd.controller.main.module;

import com.it.myd.bean.box.MsgBoard;
import com.it.myd.bean.main.ReturnValue;
import com.it.myd.bean.main.User;
import com.it.myd.service.main.module.aimsg.AiMsgService;
import com.it.myd.service.main.module.msgboard.MsgBoardService;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.List;

@Controller
@RequestMapping("/module/aimsg")
public class AiMsgController {

    @Autowired
    private AiMsgService aiMsgService;
    @Autowired
    private MsgBoardService msgBoardService;

    @RequestMapping("addMsgBoard")
    @ResponseBody
    public ReturnValue addMsgBoard(HttpServletRequest request){
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        String msg_content = request.getParameter("msg_content");
        MsgBoard msgBoard = new MsgBoard();
        msgBoard.setUser(user);
        msgBoard.setMsg_content(msg_content);
        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        msgBoard.setMsg_time(sdf.format(System.currentTimeMillis()));

        String hf = aiMsgService.completion(msg_content);
        msgBoard.setMsg_content1(hf);

        aiMsgService.saveMsg(msgBoard);

        ReturnValue returnValue = new ReturnValue();
        returnValue.isSuccess(hf);
        return returnValue;
    }

}
